/*
 * @Description: 
 * @Author: zyj
 * @Date: 2022-05-27 17:16:48
 * @LastEditors: zyj
 * @LastEditTime: 2022-05-27 17:21:28
 */
//给你一个 DOM 元素，创建一个能访问该元素所有子元素的函数，并且要将每个子元素传递给指定的回调函数。
function ElementLoop(node, cb) {
  cb(node);
  let child = node.children
  for (let i = 0; i < child.length; i++) {
    ElementLoop(child[i], cb);
  }
}


/* 判断是否是回文字符串 */
function isPalindrome(str) {
  str = str.replace(/\W/g, '').toLowerCase();
  return (str == str.split('').reverse().join(''));
}
console.log(isPalindrome('Noon'));
console.log(isPalindrome('Naon'));


/* JSON.stringify()造成的问题 */
let obj = {
  name: "张三",
  bar: null,
  foo: undefined,
  fn: function () { }
}

let a = JSON.stringify(obj);
console.log(a);  //{"name":"张三","bar":null}

/* 验证for-in会循环原型链上的可枚举属性 */
let person = {
  name: '张三',
  age: 16
}
person.__proto__.sex = 'man';
for (let key in person) {
  console.log(person[key]);
}


/* 判断字符串是否同构，eg：add => egg  title => paper */
function isIsomorphism(str1, str2) {
  if (str1.length != str2.length) return false;
  let strMap = {}
  for (let i = 0; i < str1.length; i++) {
    let letterA = str1[i],
      letterB = str2[i];
    if (strMap[letterA] === undefined) {
      strMap[letterA] = letterB;
    } else if (strMap[letterA] !== letterB) {
      return false
    }
  }
  return true
}


console.log(isIsomorphism('title', 'paper'));
console.log(isIsomorphism('title', 'papir'));